Import('env')

sources = Split("""
    Mulog.cc
    Codec.cc
    DirEntry.cc
    Muconf.cc
""")


# Check for libxml++ 2.6 or 1.0
conf = env.Configure()

import os, sys

sys.stdout.write('Checking for libxml++...')
sys.stdout.flush()

libxmlpp = None
if not os.spawnlpe(os.P_WAIT, 'pkg-config', 'pkg-config', '--exists', 'libxml++-1.0', os.environ):
    libxmlpp = 'libxml++-1.0'
elif not os.spawnlpe(os.P_WAIT, 'pkg-config', 'pkg-config', '--exists', 'libxml++-2.6', os.environ):
    libxmlpp = 'libxml++-2.6'

if libxmlpp is None:
    print
    print 'Please install libxml++-1.0 or 2.6 where pkg-config and scons can find it'
    Exit(1)

print ' ', libxmlpp

env.ParseConfig('pkg-config --cflags --libs ' + libxmlpp)
if not conf.CheckHeader('libxml++/libxml++.h', language='C++'):
    print libxmlpp, 'was found, but couldn\'t be used, bailing out'
    Exit(1)

if env['LIBXMLPP_STATIC']:
    lib = libxmlpp[3:]
    env['LIBS'].remove(lib)
    env.Append(LIBXMLPP_STATIC_LIBS = ['/usr/lib/lib%s.a' % lib])

conf.Finish()


env.StaticLibrary(target = 'muhelp', source = sources)
print